package io.github.fb513.api.controller;

import io.github.fb513.api.config.Login;
import io.github.fb513.api.facade.FriendshipFacade;
import io.github.fb513.api.model.CommonResp;
import io.github.fb513.api.model.request.FriendshipReq;
import io.github.fb513.api.model.request.RemarkReq;
import io.github.fb513.api.model.response.FriendshipResp;
import io.github.fb513.api.util.RespUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户关系表 前端控制器
 * </p>
 *
 * @author fengbo
 * @since 2023-12-30
 */
@RestController
@RequestMapping("/friend")
public class FriendshipController {

    @Autowired
    private FriendshipFacade friendshipFacade;

    @PostMapping("/add")
    public CommonResp<?> addFriend(@RequestBody FriendshipReq req) {
        return RespUtils.success(friendshipFacade.addFriend(req));
    }

    @PostMapping("/remark")
    public CommonResp<?> remarkFriend(@RequestBody RemarkReq req) {
        friendshipFacade.remarkFriend(req);
        return RespUtils.success();
    }

    @GetMapping("/list")
    public CommonResp<List<FriendshipResp>> getFriendList(@Login Long userId,
                                                          @RequestParam(required = false) Long maxSeq) {
        return RespUtils.success(friendshipFacade.offlineFriend(userId, maxSeq));
    }
}
